<template>
  <div>
    <!-- 搜索组件 -->
    <div class="filter-box">
      <el-form :inline="true">
        <el-form-item class="hc-field-item" label="标题">
          <el-input v-model="queryParam.bt" placeholder="请输入标题" clearable></el-input>
        </el-form-item>
        <el-form-item class="btn-list">
          <el-button type="primary" @click="getTableData">查询</el-button>
          <el-button type="primary" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-tabs v-model="moduleKey" @tab-click="getTableData">
      <el-tab-pane v-for="(item,index) in tabList" :key="index" :label="item.tab" :name="item.key">
      </el-tab-pane>
    </el-tabs>
    <el-table ref="hcTable" :data="tableData" :border="viewConfig.bordered" :header-cell-style="{ background: viewConfig.theadColor }" style="width: 100%" :row-key="(row) => row.unid || 0 + '_' + row.xh" stripe @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="45" :reserve-selection="true">
      </el-table-column>
      <el-table-column :label="columnsItem.title" :width="columnsItem.width" v-for="(columnsItem, index) in columns" :key="index" :align="columnsItem.align" :fixed="columnsItem.key == 'action' ? 'right' : false">
        <template slot="header" slot-scope="scope">
          <span v-html="scope.column.label"></span>
        </template>
        <template slot-scope="scope">
          <HCViewItem :text="scope.row[columnsItem.key]" :record="scope.row" :otherObj="{}" :columnsItem="columnsItem" :buttonsList="[]"></HCViewItem>
        </template>
      </el-table-column>
    </el-table>
    <!-- 页码 -->
    <div class="hc-view-page">
      <pagination v-show="totalCount > 0" :total="totalCount" :page.sync="queryParam.pageNo" :limit.sync="queryParam.pageSize" @pagination="getTableData" />
    </div>
  </div>
</template>
<script>
import { getQbglList } from "../api/module/qbgl/qbgl";
import { getSwglList } from "../api/module/swgl/swgl";
import { getFwglList } from "../api/module/fwgl/fwgl";
import { buildView } from "../api/common/moduleview";
import { mapState } from "vuex";
import { viewConfig } from "@/utils/coreConfig";
export default {
  name: "documentPaper",
  components: {
    //解决嵌套引入的问题
    HCViewItem: () => import("../HCView/components/HCViewItem.vue"),
  },
  props: ["unid", "modulename"],
  computed: {
    ...mapState("dict", ["DICT_bw_state"])
  },
  data()
  {
    return {
      viewConfig,
      columns: [
        {
          title: "标题",
          dataIndex: "bt",
          key: "bt",
          type: "TEXT"
        }
      ],
      tableData: [],
      tabList: [
        { key: "swgl", tab: "收文" },
        { key: "fwgl", tab: "发文" },
        { key: "qbgl", tab: window.HC_config.VUE_APP_QBGLNAME || "签报" },
        { key: "grzl", tab: "资料" },
        { key: "cyjgl", tab: "阅文" }
      ],
      moduleKey: "swgl",
      queryParam: {
        pageSize: 10,
        pageNo: 1,
        bt: null
      },
      totalCount: 0,
      //勾选列表
      records: []
    };
  },
  methods: {
    //获取办文数据
    getTableData(data)
    {
      let getTableData;
      if (this.moduleKey == "swgl")
      {
        getTableData = getSwglList;
      }
      else if (this.moduleKey == "fwgl")
      {
        getTableData = getFwglList;
      }
      else if (this.moduleKey == "qbgl")
      {
        buildView({
          key: 4,
          moduleName: "qbgl",
          viewType: "qbgl",
          pageSize: this.queryParam.pageSize,
          pageNum: this.queryParam.pageNo,
          queryMap: JSON.stringify({
            bt_LIKE: this.queryParam.bt
          }),
          paramsMap: JSON.stringify({})
        })
          .then((res) =>
          {
            if (res.data.tableList.result)
            {
              this.tableData = res.data.tableList.result.data || [];
              this.totalCount = res.data.tableList.result.totalCount || 0;
              //前端 给序号
              this.tableData.forEach((item, index) =>
              {
                item.yjwModuleName = this.moduleKey;
                item.xh = index +
                  1 +
                  (this.currentpage - 1) * this.pageSize;
              })
            }
          })
      }
      else if (this.moduleKey == "grzl")
      {
        buildView({
          key: 1,
          moduleName: "grzl",
          viewType: "grzl",
          pageSize: this.queryParam.pageSize,
          pageNum: this.queryParam.pageNum,
          queryMap: JSON.stringify({
            bt_LIKE: this.queryParam.bt
          }),
          paramsMap: JSON.stringify({})
        })
          .then((res) =>
          {
            if (res.data.tableList.result)
            {
              this.tableData = res.data.tableList.result.data || [];
              this.totalCount = res.data.tableList.result.totalCount || 0;
              //前端 给序号
              this.tableData.forEach((item, index) =>
              {
                item.yjwModuleName = this.moduleKey;
                item.xh = index +
                  1 +
                  (this.currentpage - 1) * this.pageSize;
              })
            }
          })
      }
      else if (this.moduleKey == "cyjgl")
      {
        buildView({
          key: 4,
          moduleName: "cyjgl",
          viewType: "cyjgl",
          pageSize: this.queryParam.pageSize,
          pageNum: this.queryParam.pageNo,
          queryMap: JSON.stringify({
            bt_LIKE: this.queryParam.bt
          }),
          paramsMap: JSON.stringify({})
        })
          .then((res) =>
          {
            if (res.data.tableList.result)
            {
              this.tableData = res.data.tableList.result.data || [];
              this.totalCount = res.data.tableList.result.totalCount || 0;
              //前端 给序号
              this.tableData.forEach((item, index) =>
              {
                item.yjwModuleName = this.moduleKey;
                item.xh = index +
                  1 +
                  (this.currentpage - 1) * this.pageSize;
              })
            }
          })
      }

      if (this.moduleKey != "grzl" && this.moduleKey != "cyjgl" && this.moduleKey != "qbgl")
      {
        getTableData(this.queryParam).then(res =>
        {
          this.totalCount = res.result.totalCount || 0;
          this.tableData = res.result.data || [];
          //前端 给序号
          this.tableData.forEach((item, index) =>
          {
            item.yjwModuleName = this.moduleKey;
            item.xh = index +
              1 +
              (this.currentpage - 1) * this.pageSize;
          })
        })
      }
    },
    reset()
    {
      this.queryParam = {
        pageSize: 10,
        pageNo: 1,
        queryBt: null
      };
    },
    //监听列表勾选
    handleSelectionChange(selection)
    {
      this.records = selection;
    },
  },

};
</script>

<style lang="scss" scoped>
.filter-box .btn-list {
  margin-bottom: 8px;
  margin-top: 8px;
}

.hc-field-item {
  margin-bottom: 8px;
  margin-top: 8px;
}
</style>